﻿using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WoChu.Infrastructure.Dapper;
using WoChu.Infrastructure.Data;
using WoChu.Infrastructure.ModelCommmon;

namespace WoChu.WMS.Repository
{
    [System.Runtime.InteropServices.GuidAttribute("1A2BCA22-D1C6-4331-A1B3-3D235EAF0E58")]
    public class GoodsRepository : RepositoryBase<Goods, int>
    {
        public GoodsRepository() : base(ConnectionsDBKey.ERP_Ora) { }

        public float GetInventory(Goods goods)
        {
            List<SqlCondition> conditions = new List<SqlCondition>() { new SqlCondition("GOODSID") };
            SearchInfo searchInfo = new SearchInfo("QTY", "v_lminv", conditions: conditions);
            return ExecuteScalar<float>(goods, searchInfo);
        }

        public void GetPageList(PageInfo<Goods, Goods> pageInfo)
        {
            string[] columns = { "GOODSID", "GOODSCODE", "GOODSNAME", "GOODSSPEC", "UNITNAME", "PURUNITNAME", "PURUNITQTY", 
                                   "STATUS", "ISPURUNITNAME", "RULECLASS" };
            List<SqlCondition> conditions = new List<SqlCondition>() { 
                new SqlCondition("GOODSCODE", OperateType.LikeBegin),new SqlCondition("GOODSNAME", OperateType.Like),
                new SqlCondition("RULECLASS"),new SqlCondition("STATUS"),
            };

            QueryPage<Goods>(pageInfo, new SearchInfo(string.Join(",", columns), orderby: "GOODSID desc",
                conditions: conditions));
            var ret = pageInfo.Result;
        }


        public int Insert(Goods entity, params string[] columns)
        {
            return base.Insert(entity, "goodsid_seq.nextval", columns);
        }

    }
}
